Add border-{top|left|bottom|right}-style properties
authorPaolo Borelli <pborelli@gnome.org>
Thu, 5 Jan 2012 15:53:43 +0000 (16:53 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:58 +0000 (18:37 +0100)
Add all the border-style subproperties and turn border-style itself in a
shorthand.

gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssstylepropertyimpl.c
tests/css/parser/value-inherit.css
tests/css/parser/value-initial.css
tests/css/parser/value-none.css
tests/css/parser/value-none.errors
tests/css/parser/value-none.ref.css

index 33d5335813b239d1a576fb38a51ae1a27aea7ce7..5d93dfd32e428cb5888b406f343be8b1dbe366fa 100644 (file)
@@ -29,6 +29,7 @@
 #include "gtkcssstylefuncsprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkprivatetypebuiltins.h"
+#include "gtktypebuiltins.h"
 
 /* this is in case round() is not provided by the compiler, 
  * such as in the case of C89 compilers, like MSVC
@@ -177,6 +178,39 @@ parse_border_color (GtkCssShorthandProperty *shorthand,
   return TRUE;
 }
 
+static gboolean
+parse_border_style (GtkCssShorthandProperty *shorthand,
+                    GValue                  *values,
+                    GtkCssParser            *parser,
+                    GFile                   *base)
+{
+  GtkBorderStyle styles[4];
+  guint i;
+
+  for (i = 0; i < 4; i++)
+    {
+      if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, (int *)&styles[i]))
+        break;
+    }
+
+  if (i == 0)
+    {
+      _gtk_css_parser_error (parser, "Expected a border style");
+      return FALSE;
+    }
+
+  for (; i < G_N_ELEMENTS (styles); i++)
+    styles[i] = styles[(i - 1) >> 1];
+
+  for (i = 0; i < G_N_ELEMENTS (styles); i++)
+    {
+      g_value_init (&values[i], GTK_TYPE_BORDER_STYLE);
+      g_value_set_enum (&values[i], styles[i]);
+    }
+
+  return TRUE;
+}
+
 static gboolean
 parse_border_image (GtkCssShorthandProperty *shorthand,
                     GValue                  *values,
@@ -691,6 +725,44 @@ pack_border_color (GValue             *value,
   gtk_style_properties_get_property (props, "border-top-color", state, value);
 }
 
+static GParameter *
+unpack_border_style (const GValue *value,
+                     guint        *n_params)
+{
+  GParameter *parameter = g_new0 (GParameter, 4);
+  GtkBorderStyle style;
+
+  style = g_value_get_enum (value);
+
+  parameter[0].name = "border-top-style";
+  g_value_init (&parameter[0].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[0].value, style);
+  parameter[1].name = "border-right-style";
+  g_value_init (&parameter[1].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[1].value, style);
+  parameter[2].name = "border-bottom-style";
+  g_value_init (&parameter[2].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[2].value, style);
+  parameter[3].name = "border-left-style";
+  g_value_init (&parameter[3].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[3].value, style);
+
+  *n_params = 4;
+  return parameter;
+}
+
+static void
+pack_border_style (GValue             *value,
+                   GtkStyleProperties *props,
+                   GtkStateFlags       state)
+{
+  /* NB: We can just resolve to a style. We pick one and stick to it.
+   * Lesson learned: Don't query border-style shorthand, query the
+   * real properties instead. */
+  g_value_unset (value);
+  gtk_style_properties_get_property (props, "border-top-style", state, value);
+}
+
 static void
 _gtk_css_shorthand_property_register (const char                        *name,
                                       GType                              value_type,
@@ -723,6 +795,7 @@ _gtk_css_shorthand_property_init_properties (void)
   const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
                                                 "border-bottom-right-radius", "border-bottom-left-radius", NULL };
   const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
+  const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
   const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
   const char *background_subproperties[] = { "background-image", "background-repeat", "background-clip", "background-origin",
                                              "background-color", NULL };
@@ -763,6 +836,12 @@ _gtk_css_shorthand_property_init_properties (void)
                                           parse_border_color,
                                           unpack_border_color,
                                           pack_border_color);
+  _gtk_css_shorthand_property_register   ("border-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          border_style_subproperties,
+                                          parse_border_style,
+                                          unpack_border_style,
+                                          pack_border_style);
   _gtk_css_shorthand_property_register   ("border-image",
                                           G_TYPE_NONE,
                                           border_image_subproperties,
index 447e1df88eb5c20ee5f0b0ce2c8c306c53e308ad..3354e16696012c5cd8f8e164236798480d6257c9 100644 (file)
@@ -715,13 +715,35 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           &no_corner_radius);
 
-  gtk_style_property_register            ("border-style",
+  gtk_style_property_register            ("border-top-style",
                                           GTK_TYPE_BORDER_STYLE,
                                           0,
                                           NULL,
                                           NULL,
                                           NULL,
                                           GTK_BORDER_STYLE_NONE);
+  gtk_style_property_register            ("border-left-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
+  gtk_style_property_register            ("border-bottom-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
+  gtk_style_property_register            ("border-right-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
+
   gtk_style_property_register            ("background-clip",
                                           GTK_TYPE_CSS_AREA,
                                           0,
index c58106b1c897235afe0ab168ff11717278dea6ff..777bbac0d10892c57b7137b76ecbb53b1ff6901a 100644 (file)
@@ -7,19 +7,22 @@
   border-bottom-color: inherit;
   border-bottom-left-radius: inherit;
   border-bottom-right-radius: inherit;
+  border-bottom-style: inherit;
   border-bottom-width: inherit;
   border-image-repeat: inherit;
   border-image-slice: inherit;
   border-image-source: inherit;
   border-image-width: inherit;
   border-left-color: inherit;
+  border-left-style: inherit;
   border-left-width: inherit;
   border-right-color: inherit;
+  border-right-style: inherit;
   border-right-width: inherit;
-  border-style: inherit;
   border-top-color: inherit;
   border-top-left-radius: inherit;
   border-top-right-radius: inherit;
+  border-top-style: inherit;
   border-top-width: inherit;
   box-shadow: inherit;
   color: inherit;
index 5abcd7e2b6aa44f1ab708b328b08f5d7a2ad5a7e..7e721661828323a47fe19d9837e2bd03636b2272 100644 (file)
@@ -7,19 +7,22 @@
   border-bottom-color: initial;
   border-bottom-left-radius: initial;
   border-bottom-right-radius: initial;
+  border-bottom-style: initial;
   border-bottom-width: initial;
   border-image-repeat: initial;
   border-image-slice: initial;
   border-image-source: initial;
   border-image-width: initial;
   border-left-color: initial;
+  border-left-style: initial;
   border-left-width: initial;
   border-right-color: initial;
+  border-right-style: initial;
   border-right-width: initial;
-  border-style: initial;
   border-top-color: initial;
   border-top-left-radius: initial;
   border-top-right-radius: initial;
+  border-top-style: initial;
   border-top-width: initial;
   box-shadow: initial;
   color: initial;
index 738d684de6f8ab16bef0541e5afd4b9c371a6592..928f5a2855142d019f4024da84107344a19769c1 100644 (file)
@@ -7,24 +7,27 @@
   border-bottom-color: none;
   border-bottom-left-radius: none;
   border-bottom-right-radius: none;
+    border-bottom-style: none;
   border-bottom-width: none;
   border-image-repeat: none;
   border-image-slice: none;
     border-image-source: none;
   border-image-width: none;
   border-left-color: none;
+    border-left-style: none;
   border-left-width: none;
   border-right-color: none;
+    border-right-style: none;
   border-right-width: none;
-    border-style: none;
   border-top-color: none;
   border-top-left-radius: none;
   border-top-right-radius: none;
+    border-top-style: none;
   border-top-width: none;
     box-shadow: none;
   color: none;
     engine: none;
-  font-family: none;
+    font-family: none;
   font-size: none;
   font-style: none;
   font-variant: none;
index f4c3de643c83ffe953ac30b6a8a94e6e293aa683..9e17c29a2cc1e7eac17b9ab344b0c95a95c4df7a 100644 (file)
@@ -5,28 +5,28 @@ value-none.css:6: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:7: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:8: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:9: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:10: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:11: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:12: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:14: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:13: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:15: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:16: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:17: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:18: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:20: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:19: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:21: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:22: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:23: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:25: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:24: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:26: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:28: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:29: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:30: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:31: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:32: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:33: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:34: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:35: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:36: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:37: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:38: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:39: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:40: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:41: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:42: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:43: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
index deadc147ad673ba0de10e68d20c34264c56b4145..660cd521c5aefa425546bdfeda765b8c844facbd 100644 (file)
@@ -1,7 +1,10 @@
 * {
   background-image: none;
+  border-bottom-style: none;
   border-image-source: none;
-  border-style: none;
+  border-left-style: none;
+  border-right-style: none;
+  border-top-style: none;
   box-shadow: none;
   engine: none;
   font-family: "none";